package com.zyj.myapplication.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.zyj.myapplication.Javabean.Club;
import com.zyj.myapplication.Model.Constant;
import com.zyj.myapplication.R;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by owner on 2017/9/27.
 */

public class SearchAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;//数据存储
    private LayoutInflater mLayoutInflater;//准备布局

    public SearchAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_clubinfo, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Club.ClubteacherEntity entity = (Club.ClubteacherEntity) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.coachName.setText(entity.getName());
        viewHolder.coachinfo.setText(entity.getIntroduction());
        Picasso.with(mContext).
                load(Constant.PIC_URL + entity.getThumb()).into(viewHolder.coachPhoto);
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView coachPhoto;
        TextView coachName, coachinfo;

        public ViewHolder(View itemView) {
            super(itemView);
            coachName = (TextView) itemView.findViewById(R.id.coachName);
            coachinfo = (TextView) itemView.findViewById(R.id.coachinfo);
            coachPhoto = (ImageView) itemView.findViewById(R.id.coachPhoto);

        }
    }
}
